package com.kinyx.framework.db.sentence.res;

import org.junit.Test;

public class _ORDER_BY_Tester_ extends SUPER {

	public void test(final String tableAlias, final int tableIdx, final Column column, final String columnName, final String fieldName, final boolean asc) {
		{
			final Order order = new Order(column.idx(tableIdx), asc);
			final _ORDER_BY sort = new _ORDER_BY(order);

			final String sentence1 = "ORDER BY" + " " + columnName + " " + (asc ? "ASC" : "DESC");
			final String sentence2 = "ORDER BY" + " " + fieldName + " " + (asc ? "ASC" : "DESC");
			final String sentence3 = "ORDER BY" + " " + tableAlias + (tableIdx == 0 ? "" : tableIdx) + "." + columnName + " " + (asc ? "ASC" : "DESC");
			final String sentence4 = "ORDER BY" + " " + tableAlias + (tableIdx == 0 ? "" : tableIdx) + "." + fieldName + " " + (asc ? "ASC" : "DESC");

			this.test_getSentence(sort, //
					sentence1, //
					sentence2, //
					sentence3, //
					sentence4 //
			);
			this.test_toString(sort, //
					"SQL: [" + sentence1 + "]", //
					"HQL: [" + sentence2 + "]", //
					"SQL: [" + sentence3 + "]", //
					"HQL: [" + sentence4 + "]" //
			);
		}
		{
			final Order order = new Order(column.idx(tableIdx), asc);
			final _ORDER_BY sort = new _ORDER_BY(order, order);

			final String sentence1 = "ORDER BY" + " " + columnName + " " + (asc ? "ASC" : "DESC") + "," + " " + columnName + " " + (asc ? "ASC" : "DESC");
			final String sentence2 = "ORDER BY" + " " + fieldName + " " + (asc ? "ASC" : "DESC") + "," + " " + fieldName + " " + (asc ? "ASC" : "DESC");
			final String sentence3 = "ORDER BY" + " " + tableAlias + (tableIdx == 0 ? "" : tableIdx) + "." + columnName + " " + (asc ? "ASC" : "DESC") + "," + " " + tableAlias + (tableIdx == 0 ? "" : tableIdx) + "." + columnName + " " + (asc ? "ASC" : "DESC");
			final String sentence4 = "ORDER BY" + " " + tableAlias + (tableIdx == 0 ? "" : tableIdx) + "." + fieldName + " " + (asc ? "ASC" : "DESC") + "," + " " + tableAlias + (tableIdx == 0 ? "" : tableIdx) + "." + fieldName + " " + (asc ? "ASC" : "DESC");

			this.test_getSentence(sort, //
					sentence1, //
					sentence2, //
					sentence3, //
					sentence4 //
			);
			this.test_toString(sort, //
					"SQL: [" + sentence1 + "]", //
					"HQL: [" + sentence2 + "]", //
					"SQL: [" + sentence3 + "]", //
					"HQL: [" + sentence4 + "]" //
			);
		}
	}

	@Test
	public void test() {
		this.list_flag.forEach(flag -> {
			this.list_tableIdx.forEach(tableIdx -> {
				this.list_column.forEach(column -> {
					this.test("demoEntity", tableIdx, column.column, column.columnName, column.fieldName, flag);
				});
			});
		});
	}

}
